package com.bcmusic.distri.service.impl;
import com.bcmusic.distri.dao.DistributeConstractMapper;
import com.bcmusic.distri.pojo.DistributeConstract;
import com.bcmusic.distri.service.DistributeConstractService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
/****
 * @Author:admin
 * @Description:DistributeConstract业务层接口实现类
 * @Date 2019/6/14 0:16
 *****/
@Service
public class DistributeConstractServiceImpl implements DistributeConstractService {

    @Autowired
    private DistributeConstractMapper distributeConstractMapper;



    /**
     * DistributeConstract构建查询对象
     * @param distributeConstract
     * @return
     */
    public Example createExample(DistributeConstract distributeConstract){
        Example example=new Example(DistributeConstract.class);
        Example.Criteria criteria = example.createCriteria();
        if(distributeConstract!=null){
            // 音乐分发合约id
            if(!StringUtils.isEmpty(distributeConstract.getConstractId())){
                    criteria.andEqualTo("constractId",distributeConstract.getConstractId());
            }
            // 分发商编号。关联distributor表的distributor_number字段。
            if(!StringUtils.isEmpty(distributeConstract.getDistributorNumber())){
                    criteria.andEqualTo("distributorNumber",distributeConstract.getDistributorNumber());
            }
            // 对应music_distribution 表的id
            if(!StringUtils.isEmpty(distributeConstract.getAuthorizationPermissionId())){
                    criteria.andEqualTo("authorizationPermissionId",distributeConstract.getAuthorizationPermissionId());
            }
            //
            if(!StringUtils.isEmpty(distributeConstract.getTransferPermissionId())){
                    criteria.andEqualTo("transferPermissionId",distributeConstract.getTransferPermissionId());
            }
            // 分发商MB分配比（=分发商自持MB分配比+终端用户MB分配比）。与管理员设定的MB交易手续分配比一致，从whole_asset表获得。比例值均乘以100保存。
            if(!StringUtils.isEmpty(distributeConstract.getDistributorRatio())){
                    criteria.andEqualTo("distributorRatio",distributeConstract.getDistributorRatio());
            }
            // 分发商自持MB分配比。由签约的分发商自行设定。
            if(!StringUtils.isEmpty(distributeConstract.getDistributorOwnRatio())){
                    criteria.andEqualTo("distributorOwnRatio",distributeConstract.getDistributorOwnRatio());
            }
            // 终端用户MB分配比。
            if(!StringUtils.isEmpty(distributeConstract.getEndUserRatio())){
                    criteria.andEqualTo("endUserRatio",distributeConstract.getEndUserRatio());
            }
            // 签约时间。即合约生成时间。
            if(!StringUtils.isEmpty(distributeConstract.getCreateTime())){
                    criteria.andEqualTo("createTime",distributeConstract.getCreateTime());
            }
            // 1为有效，0为无效
            if(!StringUtils.isEmpty(distributeConstract.getValidStatus())){
                    criteria.andEqualTo("validStatus",distributeConstract.getValidStatus());
            }
            // 是否开启分发，1表示开启，0表示不
            if(!StringUtils.isEmpty(distributeConstract.getOpenStatus())){
                    criteria.andEqualTo("openStatus",distributeConstract.getOpenStatus());
            }
            //
            if(!StringUtils.isEmpty(distributeConstract.getUpdateTime())){
                    criteria.andEqualTo("updateTime",distributeConstract.getUpdateTime());
            }
        }
        return example;
    }


}
